# Contributor: Fabian Affolter <fabian@affolter-engineering.ch>
# Maintainer: Fabian Affolter <fabian@affolter-engineering.ch>
pkgname=p11-kit
pkgver=0.23.20
pkgrel=5
pkgdesc="Library for loading and sharing PKCS#11 modules"
url="https://p11-glue.freedesktop.org/"
arch="all"
license="BSD-3-Clause"
makedepends="meson libtasn1-dev libffi-dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-trust $pkgname-server"
source="https://github.com/p11-glue/p11-kit/releases/download/$pkgver/p11-kit-$pkgver.tar.xz"

build() {
	meson \
		--prefix=/usr \
		--buildtype=plain \
		-Dtrust_paths=/etc/ssl/certs/ca-certificates.crt \
		. output
	ninja -C output
}

check() {
	ninja -C output test
}

package() {
	DESTDIR="$pkgdir" ninja -C output install
	install -Dm644 "$pkgdir"/etc/pkcs11/pkcs11.conf.example -t "$pkgdir"/usr/share/doc/$pkgname
}

trust() {
	pkgdesc="System trust module from $pkgname"
	mkdir -p "$subpkgdir"/usr/share/p11-kit/modules \
		"$subpkgdir"/usr/lib/pkcs11 \
		"$subpkgdir"/usr/bin

	mv "$pkgdir"/usr/share/p11-kit/modules/p11-kit-trust.module \
		"$subpkgdir"/usr/share/p11-kit/modules/
	mv "$pkgdir"/usr/lib/pkcs11/p11-kit-trust.so \
		"$subpkgdir"/usr/lib/pkcs11/
	mv "$pkgdir"/usr/bin/trust "$subpkgdir"/usr/bin/
}

server() {
	pkgdesc="Server and client commands for $pkgname"
	mkdir -p "$subpkgdir"/usr/lib/pkcs11 \
		"$subpkgdir"/usr/libexec/p11-kit \
		"$subpkgdir"/etc/init.d
	mv "$pkgdir"/usr/lib/pkcs11/p11-kit-client.so \
		"$subpkgdir"/usr/lib/pkcs11
	mv "$pkgdir"/usr/libexec/p11-kit/p11-kit-server \
		"$subpkgdir"/usr/libexec/p11-kit
}

sha512sums="1eb88773fdd49dd48c7e089744e9dbbf6c1033a4863f3bfe75a68d842804baa3c373cb1b28ee625dd69a6e16c89df4ac755e0928495dccf38c007c530f6cfa57  p11-kit-0.23.20.tar.xz"
